package com.xinggq.pay.service.pay.channel.yse.utils;

import java.nio.file.Paths;

/**
 * 系统工具
 */
public abstract class AppUtils {

    private static String appHome = null;

    static {
        String dirtyPath = AppUtils.class.getResource("").toString();
        String jarPath = dirtyPath.replaceAll("^.*file:", "");
        jarPath = jarPath.replaceAll("jar!.*", "jar").replaceAll("%20", "");
        if (!jarPath.endsWith(".jar")) {
            jarPath = jarPath.replaceAll("/classes/.*", "/classes/");
        }
        if (System.getProperty("os.name").contains("Win")) {
            jarPath = jarPath.substring(1);
        }
        appHome = Paths.get(jarPath).getParent().toString(); //Paths - from java 8
    }

    /**
     * 获取AppHome
     */
    public static String getAppHome() {
        return appHome;
    }
}
